package com.eastfair.cloud.util;/**
 * Created by by on 2020/12/3 15:20
 */

import com.eastfair.cloud.model.WeightEnum;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 *
 * 高:中:低 = 6:3:1
 *
 * @program: sx_cloud
 * @author: ligang
 * @create: 2020-12-03 15:20
 */
public class WeightRoleTransmit {
    /**
     * 高： 包含30-100的区间
     * 中等: 包含5-30的区间
     * 低 : 包含0-5的区间
     */
    private static float low = 30;
    private static float center = 5;

    /**
     * 随机匹配权重
     *
     * @return
     */
    public static WeightEnum findOneWeight() {
        int ran1 = new Random().nextInt(100);
        if (ran1 >= low) {
            return WeightEnum.HIGH;
        } else if (ran1 >= center && ran1 < low) {
            return WeightEnum.CENTER;
        } else if (ran1 < center) {
            return WeightEnum.LOW;
        }
        return WeightEnum.HIGH;
    }

    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < 100; i++) {
            WeightEnum weightEnum = findOneWeight();
            if (map.get(weightEnum.getType()) == null) {
                map.put(weightEnum.getType(), 1);
            } else {
                map.put(weightEnum.getType(), map.get(weightEnum.getType()) + 1);
            }

        }
        System.out.println(map);

    }

}
